﻿using System;
using System.Data;
using System.Collections.Generic;
using Chenxin.Lib.Business.Entity;
namespace Chenxin.Lib.Business.BLL
{
    /// <summary>
    /// 业务逻辑类ContractCommisionIncomeHistory 的摘要说明。
    /// </summary>
    public class ContractCommisionIncomeHistory
    {
        public ContractCommisionIncomeHistory()
        { }
        #region  成员方法
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Chenxin.Lib.Business.Entity.ContractCommisionIncomeHistory model)
        {
            Chenxin.Lib.Business.DAL.ContractCommisionIncomeHistory.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Chenxin.Lib.Business.Entity.ContractCommisionIncomeHistory model)
        {
            Chenxin.Lib.Business.DAL.ContractCommisionIncomeHistory.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(Guid RecordId)
        {

            Chenxin.Lib.Business.DAL.ContractCommisionIncomeHistory.Delete(RecordId);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Chenxin.Lib.Business.Entity.ContractCommisionIncomeHistory GetModel(Guid RecordId)
        {

            return Chenxin.Lib.Business.DAL.ContractCommisionIncomeHistory.GetModel(RecordId);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return Chenxin.Lib.Business.DAL.ContractCommisionIncomeHistory.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.Business.Entity.ContractCommisionIncomeHistory> GetModelList(string strWhere)
        {
            DataSet ds = Chenxin.Lib.Business.DAL.ContractCommisionIncomeHistory.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Chenxin.Lib.Business.Entity.ContractCommisionIncomeHistory> DataTableToList(DataTable dt)
        {
            List<Chenxin.Lib.Business.Entity.ContractCommisionIncomeHistory> modelList = new List<Chenxin.Lib.Business.Entity.ContractCommisionIncomeHistory>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Chenxin.Lib.Business.Entity.ContractCommisionIncomeHistory model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Chenxin.Lib.Business.Entity.ContractCommisionIncomeHistory();
                    if (dt.Rows[n]["RecordId"].ToString() != "")
                    {
                        model.RecordId = new Guid(dt.Rows[n]["RecordId"].ToString());
                    }
                    if (dt.Rows[n]["ContractId"].ToString() != "")
                    {
                        model.ContractId = new Guid(dt.Rows[n]["ContractId"].ToString());
                    }
                    model.IncomeType = dt.Rows[n]["IncomeType"].ToString();
                    if (dt.Rows[n]["Income"].ToString() != "")
                    {
                        model.Income = decimal.Parse(dt.Rows[n]["Income"].ToString());
                    }
                    if (dt.Rows[n]["AddTime"].ToString() != "")
                    {
                        model.AddTime = DateTime.Parse(dt.Rows[n]["AddTime"].ToString());
                    }
                    if (dt.Rows[n]["AddUserId"].ToString() != "")
                    {
                        model.AddUserId = new Guid(dt.Rows[n]["AddUserId"].ToString());
                    }
                    model.AddUserName = dt.Rows[n]["AddUserName"].ToString();
                    if (dt.Rows[n]["AddDepartId"].ToString() != "")
                    {
                        model.AddDepartId = new Guid(dt.Rows[n]["AddDepartId"].ToString());
                    }
                    model.AddDepartName = dt.Rows[n]["AddDepartName"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 根据成交编号获得数据列表
        /// </summary>
        public DataSet GetListByParams(Dictionary<string, string> dicParams)
        {
            System.Text.StringBuilder strWhere = new System.Text.StringBuilder();
            int PageSize = 10;
            int PageIndex = 1;

            string TableName = "t_Contract_CommisionIncomeHistory";
            string OrderField = "t_Contract_CommisionIncomeHistory.Addtime DESC";
            string FieldList = "IncomeType,Income,AddTime,AddUserName";
            string TableFieldList = "IncomeType,Income,AddTime,AddUserName";

            strWhere.Append(" 1=1 ");
            if (dicParams.ContainsKey("PageSize"))
            {
                PageSize = Convert.ToInt32(dicParams["PageSize"]);
            }
            if (dicParams.ContainsKey("PageIndex"))
            {
                PageIndex = Convert.ToInt32(dicParams["PageIndex"]) + 1;
            }
            if (dicParams.ContainsKey("Sort"))
            {
                OrderField = dicParams["Sort"];
            }
            if (dicParams.ContainsKey("ContractId"))
            {
                strWhere.AppendFormat("And ContractId='{0}'", dicParams["ContractId"]);
            }
            if (dicParams.ContainsKey("IncomeType"))
            {
                strWhere.AppendFormat("And IncomeType='{0}'", dicParams["IncomeType"]);
            }

            return Chenxin.Lib.Business.DAL.ContractCommisionIncomeHistory.GetPartList(PageSize, PageIndex, OrderField, TableName, strWhere.ToString(), FieldList, TableFieldList, true);
        }
        #endregion  成员方法
    }
}

